#define DETEC_MAX(a ,b) ((a > b) ? a : b)
#define DETEC_MIN(a ,b) ((a < b) ? a : b)
#define CLAP(a) (DETEC_MAX((DETEC_MIN(a, 0xff)), 0x00)) 


//already quan.y[16,235],uv[16,240]
int get_rgb_by_yuv_pixel(int Y, int U, int V, unsigned char* R, unsigned char* G, unsigned char* B)
{		
#if 0
	#if 0
	*R = Y + 1.4075 *(V-128);
	*G = Y - 0.3455 *(U-128) - 0.7169 * (V-128);
	*B = Y + 1.779 * (U-128);
	#else
	U = U - 128;
	V = V - 128;
	int rdif = V + ((V*103) >> 8);
	int invgdif = ((U*88) >> 8) + ((V*183) >> 8);
	int bdif = U+((U*198) >> 8);
	int _r,_g,_b;
	_r = Y + rdif;
	_g = Y - invgdif;
	_b = Y + bdif;
	*R = CLAP(_r);
	*G = CLAP(_g);
	*B = CLAP(_b);
	#endif
#else
	
	int _R = (298*Y + 411 * V - 57344)>>8;
	int _G = (298*Y - 101* U - 211* V+ 34739)>>8;
	int _B = (298*Y + 519* U- 71117)>>8;
	*R = CLAP(_R);
	*G = CLAP(_G);
	*B = CLAP(_B);
	/*
	*R = (298*Y + 411 * V - 57344)>>8;
	*G = (298*Y - 101* U - 211* V+ 34739)>>8;
	*B = (298*Y + 519* U- 71117)>>8;
	*/

#endif
	return 0;
}

